package io.gitee.zhangbinhub.admin.po

import io.gitee.zhangbinhub.acp.core.common.CommonTools
import io.gitee.zhangbinhub.admin.component.DbConstant
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.Min

import jakarta.validation.constraints.NotNull

/**
 * @author zhang by 11/01/2019
 * @since JDK 11
 */
@Schema(description = "分页查询参数")
class QueryParam {
    @Schema(description = "当前页号", requiredMode = Schema.RequiredMode.REQUIRED)
    @get:NotNull(message = "当前页号不能为空")
    @get:Min(value = 1, message = "当前页号不能小于1")
    var currPage: Int? = 1

    @Schema(description = "每页记录数", requiredMode = Schema.RequiredMode.REQUIRED)
    @get:NotNull(message = "每页记录数不能为空")
    @get:Min(value = 1, message = "每页记录数不能小于1")
    var pageSize: Int? = 10

    @Schema(description = "排序列名，多列以“,”分隔")
    var orderName: String? = null
        get() {
            return if (field != null && CommonTools.regexPattern(DbConstant.ORDER_NAME_PATTERN, field!!)) {
                field
            } else {
                null
            }
        }

    @Schema(description = "排序方式", allowableValues = ["asc", "desc"])
    var orderCommand: String? = "desc"
        get() {
            return if (field == null || field!!.startsWith("desc", ignoreCase = true)) {
                "desc"
            } else {
                "asc"
            }
        }
}
